package com.example.activityproject201202;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    //创建
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.i("MainActivity","启动了onCreate~~");
        Button to_one_act_bt = findViewById(R.id.to_one_act_bt);
         Button to_red_act_bt = findViewById(R.id.to_red_act_bt);
        Button to_blue_act_bt = findViewById(R.id.to_blue_act_bt);
        Button to_listener_act_bt = findViewById(R.id.to_listener_act_bt);
        to_listener_act_bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, ListenerAct.class);
                startActivity(intent);
            }
        });


        to_red_act_bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, RedAct.class);
                intent.putExtra("to_red_key","Msg From MainActivity");
                startActivity(intent);
            }
        });
        to_blue_act_bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, BlueAct.class);
                Bundle bundle = new Bundle();
                bundle.putString("name","李白");
                bundle.putString("age","18");
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });

        to_one_act_bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //跳到OneActivtiy
                Intent intent = new Intent(MainActivity.this, OneActivity.class);
                User user = new User();
                user.setName("韩信");
                user.setAge("28");
                intent.putExtra("user_key",user);
                startActivity(intent);

            }
        });
        EditText input_et = findViewById(R.id.input_et);

        input_et.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                Editable text = input_et.getText();


            }
        });
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        String msg_content= intent.getStringExtra("msg_key");
        //toast提示框
        Toast.makeText(this, msg_content, Toast.LENGTH_SHORT).show();

    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.i("MainActivity","onStart~~");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.i("MainActivity","onResume~~");
    }


    @Override
    protected void onPause() {
        super.onPause();
        Log.i("MainActivity","onPause~~");
    }


    @Override
    protected void onStop() {
        super.onStop();
        Log.i("MainActivity","onStop~~");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.i("MainActivity","onDestroy~~");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.i("MainActivity","onRestart~~");
    }
}